package cn.ecnu.mapper.personal;

import cn.ecnu.pojo.personal.Contact;
import cn.ecnu.pojo.personal.Title;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ContactMapper extends BaseMapper<Contact> {

    @Select("SELECT t.* " +
            "FROM title AS t " +
            "WHERE t.user_id IN " +
            "   (SELECT ${target}" +
            "    FROM contact AS c" +
            "    WHERE c.${role}=#{user_id} AND c.relation=#{relation})")
    @Result(column = "labels",property = "labels",typeHandler = JacksonTypeHandler.class)
    List<Title> listSpecificTitles(@Param("role")String roleId,
                                          @Param("target")String targetId,
                                          @Param("user_id")Integer userId,
                                          @Param("relation")Integer relation);

//    @Insert("INSERT INTO contact " +
//            "(candidate_id, recommender_id, relation) " +
//            "values " +
//            "(#{candidateId}, #{recommenderId},#{relation}) " +
//            "ON DUPLICATE KEY UPDATE " +
//            "candidate_id=#{candidateId},recommender_id=#{recommenderId},relation=#{relation}")
//    public int saveOrUpdateByMulId(Contact contact);
}
